package alexattar.gdxtest.screens;

import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;

import com.badlogic.gdx.graphics.Color;

import alexattar.gdxtest.GdxTestGame;
import alexattar.gdxtest.Level;
import alexattar.gdxtest.Profile;
import alexattar.gdxtest.screens.scene2d.Ship2D;
import alexattar.gdxtest.services.MusicManager.TyrianMusic;

public class LevelScreen extends AbstractScreen {

	private final Profile profile;
	private final Level level;
	
	private Ship2D ship2d;
	
	public LevelScreen(GdxTestGame game, int targetLevelId) {
		super(game);
		profile = game.getProfileManager().retrieveProfile();
		level = game.getLevelManager().findLevelById(targetLevelId);
	}
	
	@Override
	protected boolean isGameScreen() {
		return true;
	}
	
	@Override
	public void show() {
		super.show();
		game.getMusicManager().play(TyrianMusic.LEVEL);
		
		ship2d = Ship2D.create(profile.getShip(), getAtlas());
		
		ship2d.setX(stage.getWidth()/2 - ship2d.getWidth() / 2);
		ship2d.setY(ship2d.getHeight());
		
		stage.addActor(ship2d);
		
		Color rootColor = stage.getRoot().getColor();
		rootColor.a = 0f;
		stage.getRoot().setColor(rootColor);
		stage.getRoot().addAction(fadeIn(0.5f));
	}
}
